/**
 *  全局脚本
 *  @author zx
 * */
function showIcon(that){
    let $_this = $(that);
    let shows = $('.shows');
    if ( shows.length > 0 ) {
        shows.remove();
    }
    $_this.parent().css('position','relative');
    let html = "<ul class='shows'><li>载入中...</li></ul>";
    $_this.after(html);
    $.ajax({
        type: 'GET',
        url: '/admin/icon',
        dataType: 'json',
        async:true,
        success: function(data){
            if ( data.code == 200 ) {
                $('.shows').remove();
                html = "<ul class='shows'>";
                $.each(data.data.icon, function (index, item) {
                    html += "<li class='checks'><i class=\"Hui-iconfont\">"+item+"</i></li>";
                });
                html += '</ul>';
                $_this.after(html);
            } else {
                layer.msg('服务错误!',{icon:5,time:1000});
            }
        },
        error:function(XmlHttpRequest, textStatus, errorThrown){
            shows.remove();
            let errstr = XmlHttpRequest.responseText;
            if ( errstr ) {
                layer.msg($.parseJSON(errstr).message,{icon:5,time:1000});
            } else {
                layer.msg('服务错误!',{icon:5,time:1000});
            }
        }
    });
}
function isMobile(){
    let ua = navigator.userAgent;

    let ipad = ua.match(/(iPad).*OS\s([\d_]+)/),

        isIphone =!ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),

        isAndroid = ua.match(/(Android)\s+([\d.]+)/);

    return isIphone || isAndroid;
}
$(function(){
    $(document).on('click', function(event){
        if($(event.target).attr("id") !== 'icon' && $(event.src).attr("id") !== "icon"){
            $(".shows").remove();
        }
    });
    $(document).on('click','.checks',function(){
        let $_this = $(this);
        $('#icon').val($_this.children('i').html());
    })
    $('.showImg').click(function(){
        let $_this = $(this);
        let src = $_this.attr('src');
        if ( !src ) {
            layer.msg('查看图片出错',{icon:5,time:1000});
            return false;
        }
        let html = '<div class="showImgDiv" style="position:fixed;width:100%;height:100%;background-color:rgba(99,99,99,0.8);z-index:999;top:0;text-align:center;line-height:100vh;"><img src="'+src+'"/></div>';
        $('body').append(html);
    });
    $(document).on('click','.showImgDiv', function () {
        $(this).remove();
    })
});